package com.yyds.blackmagic.service.impl;

import com.yyds.blackmagic.entity.AdminPermission;
import com.yyds.blackmagic.mapper.AdminPermissionMapper;
import com.yyds.blackmagic.service.AdminPermissionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author ccc
 * @Date 2021/12/17
 * @Descripton
 */
@Service
public class AdminPermissionServiceImpl implements AdminPermissionService {
    @Resource
    AdminPermissionMapper adminPermissionMapper;

    @Override
    public List<AdminPermission> findPermsByRoleId (Integer id) {
        List<AdminPermission> perms = adminPermissionMapper.findPermsByRoleId (id);
        return perms;
    }

    @Override
    public List<AdminPermission> findAll () {
        List<AdminPermission> adminPermissions =  adminPermissionMapper.findAll();
        return adminPermissions;
    }

    @Override
    public int update (Integer id, List<AdminPermission> perms) {
        int res =  adminPermissionMapper.deleteAllPermissionByRoleId(id);
        int res1 = 0;
        for (AdminPermission perm : perms) {
            res1+= adminPermissionMapper.add(id,perm.getId ());
        }
        return res1;
    }
}
